let swiper = {
  refresh : function (this_o) {
    let str = "";
    $.ajax({
      url: "/admin/swipers",
      success: function (res) {
        console.log(res);
        // console.log(Boolean(-1));
        res.data.forEach((item) => {
          let url = `http://localhost:8888/uploads/${item.swiperimg}`;
          console.log(item.swiperstatus - 2);
          let g =
            item.swiperstatus - 2
              ? `<span
        data-status="2"
        class="layui-badge layui-bg-green"
        >√</span
      >`
              : `<span
        data-status="1"
        class="layui-badge layui-bg-cyan"
        >×</span
      >`;
          str += `  <tr>
          <td>${item.id}</td>
          <td><img src='${url}'></td>
          <td>${item.swiperimg}</td>
          <td id='con'>${g} </td>
          <td><button
        type="button"
        class="layui-btn layui-btn-xs layui-btn-danger delete"
      >
        删除
      </button></td>
        </tr>`;
          $("tbody").html(str);
        });
      },
    });
  },
  addpng: function (this_o) {
    let fd = new FormData();
        let newfiles = Array.from(this_o[0].files);
        newfiles.forEach((item) => {
          console.log(item);
          fd.append("swipers", item);
        });
        $.ajax({
          type: "POST",
          url: `/admin/swipers`,
          data: fd,
          processData: false,
          contentType: false,
          success: function (res) {
            console.log(res);
          },
        });
  },
  putsta: function (this_o) {
    let id = this_o.parents("tr").children().first().text();
        let sta = this_o.children("span").data("status");
        sta = (sta + 3) % 2 ? 2 : 1;
        console.log(sta);
        $.ajax({
          type: "PUT",
          url: `/admin/swipers/${id}`,
          data: { status: sta },
          success: function (res) {
            console.log(res);
            let g =
              sta - 2
                ? `<span
            data-status="2"
            class="layui-badge layui-bg-green"
            >√</span
          >`
                : `<span
            data-status="1"
            class="layui-badge layui-bg-cyan"
            >×</span
          >`;

            this_o.html(g);
          },
        });
  },
  delimg: function (this_o) {
    layer.confirm(
      "Are you sure you want to delete it?",
      { icon: 3, title: "提示" },
      function (index) {
        // do something
        this_o.parents("tr").hide();
        let id = this_o.parents("tr").children().first().text();
        console.log(id);
        $.ajax({
          type: "DELETE",
          url: `/admin/swipers/${id}`,
          success: function (res) {
            console.log(res);
          },
        });
        layer.close(index);
      })
    
  }
}